package me.zhengjie.excel;

import com.alibaba.excel.EasyExcel;
import me.zhengjie.dao.ContainerDao;
import me.zhengjie.dao.StoreLocalDao;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;


public class DataHandle {

    public static void HandleStoreData(String filePath, List<StoreLocalDao> storageList) {
        try {
            ReadStoreListener dataListener = new ReadStoreListener();
            // 执行读取操作
            EasyExcel.read(filePath, ReadStoreVo.class, dataListener)
                    .sheet()
                    .doRead();
            List<ReadStoreVo> dataList = dataListener.getDataList();

            for (ReadStoreVo read : dataList) {
                StoreLocalDao storeLocalDao = new StoreLocalDao();

                String storeCode = read.getStoreCode();
                String[] split = storeCode.split("-");
                if (split.length != 4)
                    return;
                String floor = split[0];
                String region = split[1];
                String serial = split[2];
                String frame = split[3];
                String wareType = read.getWareType();

                // Integer isExist = read.getIsExist();
                Integer status = 0;//isExist == 1 ? 3 : 0;
                Integer isLock = read.getIsLock();
                String storeType = read.getStoreType();
                String goodType = read.getGoodType();

                String containerCode = read.getContainerCode();

                Double weight = read.getWeight();
                Double sLong = read.getSLong();
                Double sWide = read.getSWide();
                Double sTall = read.getSTall();

                storeLocalDao.setFloor(floor);
                storeLocalDao.setRegion(region);
                storeLocalDao.setSerial(serial);
                storeLocalDao.setFrame(frame);
                storeLocalDao.setWareType(wareType);
                storeLocalDao.setId(storeCode);
//                storeLocalDao.setStoreName(storeName);
                storeLocalDao.setStoreType(storeType);
                storeLocalDao.setGoodType("普通货架");
                storeLocalDao.setIsLock(0);
                storeLocalDao.setStatus(status);
                storeLocalDao.setContainerCode(containerCode);
                Date date = new Date();
                storeLocalDao.setCreateDate(new Timestamp(date.getTime()));
                storeLocalDao.setWeight(weight);
                storeLocalDao.setSLong(sLong);
                storeLocalDao.setSWide(sWide);
                storeLocalDao.setSTall(sTall);
                storageList.add(storeLocalDao);
            }
        } catch (Exception e) {
            System.out.println("**********MMMMM"+e.getMessage());
        }
    }

    public static void HandleContainerData(String filePath, List<ContainerDao> containerList) {
        ReadContainerListener dataListener = new ReadContainerListener();
        EasyExcel.read(filePath, ReadContainerVo.class, dataListener)
                .sheet()
                .doRead();
        List<ReadContainerVo> dataList = dataListener.getDataList();

        for (ReadContainerVo containerVo : dataList) {
            ContainerDao containerDao = new ContainerDao();
            containerDao.setId(containerVo.getId());
            containerDao.setType(containerVo.getType());
            containerDao.setLocal(containerVo.getLocal());
            containerDao.setDisable(containerVo.getDisable());
            containerDao.setBarCodeBad(containerVo.getBarCodeBad());
            containerDao.setContainerBad(containerVo.getContainerBad());
            containerDao.setCreateDate(new Timestamp(new Date().getTime()));
            containerDao.setWeight(containerVo.getWeight());
            containerDao.setWLong(containerVo.getWeight());
            containerDao.setWWide(containerVo.getWeight());
            containerDao.setWTall(containerVo.getWeight());
            containerDao.setIsExist(0);
            containerList.add(containerDao);
        }
    }
}
